orderListController.$inject = ['$scope', '$rootScope', 'orderService'];

function orderListController($scope, $rootScope, orderService) {
    
    $scope.orders = [];
    
    /**
     * wait until customer id is got
     */
    $rootScope.$on('loginedCustomer', function() {
        if ($rootScope.globalData.loginedCustomer) {
            orderService.getOrderListByCustomerId($rootScope.globalData.loginedCustomer._id).then(
                function(response) {
                    if (response.data.result) {
                        $scope.orders = response.data.data;
                    }
                },
                function(err) {
                    console.log(err.data);
                }
            );
        }
    });
    
}

module.exports = orderListController;